#!/usr/bin/env python

import os,sys

if len(sys.argv) < 2:
    sys.exit('argument missing')

file_from = open(sys.argv[1])
file_to_dir = ''

if len(sys.argv) >= 3:
    file_to_dir = sys.argv[2]

def file_to_write(num):
    return open(os.path.join(file_to_dir, '%02d.txt' % num), 'w')

seq = 0;
line_counter = 0;
file_to = file_to_write(seq)

for line in file_from.readlines():
    file_to.write(line)
    line_counter += 1
    if (line_counter == 2000):
        file_to.close()
        seq += 1
        file_to = file_to_write(seq)
        line_counter = 0

file_to.close()
file_from.close()
